<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 避免回调地狱 -->
  <script>
    /* 1 */
    function one() {
      setTimeout(() => {
        console.log('1');
        Print.next();
      }, 1000)
    }
    function two() {
      setTimeout(() => {
        console.log('2');
        Print.next();
      }, 2000)
    }
    function three() {
      setTimeout(() => {
        console.log('3');
        Print.next();
      }, 3000)
    }
    //声明生成器函数
    function* printData() {
      yield one()
      yield two();
      yield three();
    }
    //调用生成器函数
    let Print = printData()
    Print.next()
        /* 2 */
        //next()括号内可传值
  </script>
</body>

</html>